#ifndef _PLAYER_H_
#define _PLAYER_H_


/*  y  k  u      7  8  9
 *   \ | /        \ | /
 *  h- . -l      4- . -6
 *   / | \        / | \
 *  b  j  n      1  2  3 */
 
/* Never forget that DIR_X != X. */
 
enum {
  DIR_1,
  DIR_2,
  DIR_3,
  DIR_4,
  DIR_NULL,
  DIR_6,
  DIR_7,
  DIR_8,
  DIR_9,
  DIR_MAX
};

enum {
  MOTION = 8,
  PLAYER_LEV_MAX = 17,
  DODGED_DAMAGE = G_MAXUINT,
  PLAYER_FOOD_MAX = 100,
  INVENTORY_MAX = 22
};

enum {
  STATUS_NORMAL,
  STATUS_POISON,
  STATUS_SLEEP,
  STATUS_CONFUSE,
  STATUS_BLIND,
  STATUS_SLEEP_MONSTERHOUSE
};

struct _status {
  gint type;
  guint time;
};

struct _player {
  struct _coord coord;
  direction dir;
  struct _status status;
  int exp;
  int lev;
  int mhp;
  int chp;
  int cstr;
  int mstr;
  int atk;
  int food;
  int food_count;
  int regen_count;
  guint damage;
  gchar died_from[32];
  struct _object *weapon;
  struct _object *shield;
  struct _object *arrow;
  struct _object *ring;
  GList *inventory_list;
  struct _sprite *sprite;
  struct _task *task;
};

struct _player Player;
int lev_exp_table[PLAYER_LEV_MAX];
SDL_Surface *surface_player_idle[DIR_MAX][ANIME_J];
SDL_Surface *surface_player_attack[DIR_MAX][ANIME_J];
SDL_Surface *surface_player_damage[DIR_MAX][ANIME_J];

int motion_end(struct _task *task);
direction ddd(int i);
int ddx(direction dir);
int ddy(direction dir);
direction lefthand(int count, direction dir);
direction opposite(direction dir);
struct _coord coord_dd(struct _coord cur_coord, direction dir);
int distance(struct _coord c1, struct _coord c2);
int animecount(struct _task *task);
void take_hit(struct _player *player, guint damage, const gchar *format, ...);
gboolean is_passable(struct _coord coord, direction dir);
void disturb();
void player_trans_state(state (*fp)(struct _task *task), struct _player *player);
struct _player *is_player(struct _coord coord);
void player_init();
void player_free();
struct _player *player_add();
state player_turn_start(struct _task *task);
state player_action_start(struct _task *task);
state player_action_end(struct _task *task);
state player_turn_end(struct _task *task);
state player_move(struct _task *task);
state move_player_anime(struct _task *task);
state player_move_running(struct _task *task);
state player_attack(struct _task *task);
state player_fire_arrow(struct _task *task);
state player_pickup(struct _task *task);
state player_down_stair(struct _task *task);
state player_up_stair(struct _task *task);
state player_lev_up(struct _task *task);
state player_get_amulet_of_yendor(struct _task *task);
state player_killed(struct _task *task);
#endif
